﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;
using UniMana.Data;

namespace UniMana.Data
{
    public class Graduate_ExamInfo
    {
          #region /*Không thay đổi*/
            public bds m_bds = new bds();

            public void Save()
            {
                m_bds.EndEdit();
                m_data.m_DCSave.SubmitChanges();
            }

            #endregion /*Không thay đổi*/
            private DBMain m_data = new DBMain();
            #region [Properties - Thuộc tính]
            public Graduate_Exam Properties
            {
                get { return m_bds.Current as Graduate_Exam; }
            }
            #endregion

            public Graduate_ExamInfo(int examKey=0)
            {
                var Iquery = m_data.m_DCSave.Graduate_Exams.Where(p=>p.Graduate_ExamKey == examKey);
                m_bds.DataSource = Iquery;
                var Row = Iquery.FirstOrDefault();
                if (Row == null)
                {
                    Graduate_Exam exam = new Graduate_Exam();
                    exam.Graduate_ExamKey = examKey;
                    Row = exam;
                    m_bds.Add(Row);
                    //m_bds.MoveLast();
                }
            }
            public Graduate_ExamInfo(string examID , DateTime dateExam)
            {
                var Iquery = m_data.m_DCSave.Graduate_Exams.Where(p => p.ExamID == examID && p.DateExam == dateExam);
                m_bds.DataSource = Iquery;
                var Row = Iquery.FirstOrDefault();
                if (Row == null)
                {
                    Graduate_Exam exam = new Graduate_Exam();
                    exam.ExamID = examID;
                    exam.DateExam = dateExam;
                    Row = exam;
                    //m_bds.Add(Row);
                    //m_bds.MoveLast();
                }
            }
            public void Delete()
            {
                m_bds.DeleteCurrent();
            }
    }
}
